package com.lx.commonlib.listener;

import android.view.View;

import com.lx.commonlib.utils.LogUtil;

/**
 * 类说明：自定义的OncLickListener
 * Created by liuxiong on 2020/1/13.
 */
public abstract  class CustomOnClickListener implements View.OnClickListener {
    public static final String TAG= CustomOnClickListener.class.getSimpleName()+"----";

    //最后一次有效点击的时间
    private long lastClickTime=0;

    //防止重复点击的时间间隔
    private long timeSpan=500L;

    @Override
    public void onClick(View view) {
        long currentTime = System.currentTimeMillis();
        if(currentTime-lastClickTime>=timeSpan){  //超过时间间隔，是有效点击
            //执行方法
            onEffectiveClick(view);
            //记录时间
            lastClickTime=currentTime;
            LogUtil.d(TAG,"有效点击");
        }else{
            LogUtil.d(TAG,"无效点击，上次有效点击在"+(currentTime-lastClickTime)+"ms之前");
        }

    }

    
    /**
    * 方法说明:  有效的点击事件
    * created by liuxiong on 2020/1/13 10:48
    */
    public abstract  void onEffectiveClick(View view);
}
